package com.hanson.controller;

import com.hanson.common.bean.ResultMessage;
import com.hanson.entity.UserBean;
import com.hanson.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/web/user")
public class WebUserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public ResultMessage add(@RequestBody UserBean userBean, @CookieValue("openId") String openId) throws Exception {
        ResultMessage resultMessage = new ResultMessage();
        UserBean returnBean = userService.selectByOpenId(openId);
        if (null != returnBean) {
            userBean.setId(returnBean.getId());
            userService.updateUser(userBean);
        }
        resultMessage.setMsg("操作成功！");
        return resultMessage;
    }
}
